<template>
  <div class="ScorePage">
    得分：{{totalScore}}
  </div>
</template>

<script>
import { mapState,mapActions } from 'vuex'

export default {
  name: 'ScorePage',
  data () {
    return {
      correctResult:['01', '01', '01','01'], //正确答案
      score: 25, //每题分数
      totalScore:0,
    }
  },
  created(){
    this.countFun();
  },
  methods:{
    ...mapActions([
      'initData',
    ]),
    countFun(){
      console.log(this.userAnswer);
      console.log(this.correctResult);
      for (var i=0 ;i<this.userAnswer.length; i++){
        if (this.userAnswer[i] == this.correctResult[i]){
          this.totalScore += this.score;
        }
      }
    }
  },
  computed:mapState([
    'userAnswer'
  ]),
  destroyed:function(){
    this.initData();
    console.log('destroyed:组件的数据绑定、监听...都去掉了,只剩下dom空壳，这里也可以善后')
  }
}
</script>

<style scoped>
</style>
